package com.example.test.service;

import com.example.test.dao.UserMapper;
import com.example.test.entity.PageBean;
import com.example.test.entity.User;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserService {

    @Resource
    private UserMapper userMapper;

    public List<User> findList(){
        return userMapper.findList();
    }

    public PageBean<User> findItemByPage(int currentPage,int pageSize) {
        //设置分页信息，分别是当前页数和每页显示的总记录数【记住：必须在mapper接口中的方法执行之前设置该分页信息】
        PageHelper.startPage(currentPage, pageSize);

        List<User> allItems = userMapper.findList();        //全部商品
        int countNums = userMapper.countItem();            //总记录数
        PageBean<User> pageData = new PageBean<>(currentPage, pageSize, countNums);
        pageData.setItems(allItems);
        return pageData;
    }
}
